package at.jaki.ubb.crawling.demo;

import java.io.File;

import org.apache.log4j.Logger;
import org.apache.log4j.xml.DOMConfigurator;

import at.jaki.ubb.crawling.api.CrawlingEngine;
import at.jaki.ubb.crawling.core.CrawlingEngineImpl;
import at.jaki.ubb.crawling.demo.ui.Listener;
import at.jaki.ubb.crawling.demo.ui.UiManager;

public class Core {

	private static final Logger LOG = Logger.getLogger(Core.class);

	/**
	 * log4j config file location
	 */
	public static final String LOG4J = "config" + File.separatorChar + "log4j.xml";

	/**
	 * Will initialize log4J
	 */
	private static void initLog4j() {
		String log4j = LOG4J;
		DOMConfigurator.configure(log4j);
		LOG.info("Loaded log configuration from " + log4j);
	}

	public static void main(String[] args) {
		initLog4j();
		Core core = new Core();
		core.start();
	}

	public void start() {
		initEngineAndUi();
	}

	private void initEngineAndUi() {
		CrawlingEngine ce = new CrawlingEngineImpl();
		Listener listener = new Listener(ce);
		UiManager.getInstance().init(ce, listener);

		ce.start(CofingGenerator.createMainConfig());
	}

}
